#ifndef VECTOR_2D
#define VECTOR_2D

#include <math.h>
#include "../define.h"

namespace sleek
{
    namespace core
    {
        namespace math
        {
            template<typename T>
            struct vector2d
            {
                vector2d() { width = 0; height = 0; }
                explicit vector2d(T s) { width = s; height = s; }
                vector2d(T w, T h) { width = w; height = h; }
                vector2d(const vector2d<T>& other) : width(other.width), height(other.height) {}
                ~vector2d() {}

                inline vector2d<T> operator + (vector2d<T> other)
                {
                    vector2d<T> n(width,height);
                    n.width += other.width;
                    n.height += other.height;
                    return n;
                }
                inline vector2d<T> operator + (T other)
                {
                    vector2d<T> n(width,height);
                    n.width += other;
                    n.height += other;
                    return n;
                }
                inline vector2d<T> operator - (vector2d<T> other)
                {
                    vector2d<T> n(width,height);
                    n.width -= other.width;
                    n.height -= other.height;
                    return n;
                }
                inline vector2d<T> operator - (T other)
                {
                    vector2d<T> n(width,height);
                    n.width -= other;
                    n.height -= other;
                    return n;
                }
                inline vector2d<T> operator / (vector2d<T> other)
                {
                    vector2d<T> n(width,height);
                    n.width /= other.width;
                    n.height /= other.height;
                    return n;
                }
                inline vector2d<T> operator / (T other)
                {
                    vector2d<T> n(width,height);
                    n.width /= other;
                    n.height /= other;
                    return n;
                }
                inline vector2d<T> operator * (vector2d<T> other)
                {
                    vector2d<T> n(width,height);
                    n.width *= other.width;
                    n.height *= other.height;
                    return n;
                }
                inline vector2d<T> operator * (T other)
                {
                    vector2d<T> n(width,height);
                    n.width *= other;
                    n.height *= other;
                    return n;
                }
                inline vector2d<T> operator = (vector2d<T> other)
                {
                    width = other.width;
                    height = other.height;
                    return *this;
                }

                inline bool operator < (vector2d<T> other) { return (width < other.width && height < other.height) ? true : false; }
                inline bool operator > (vector2d<T> other) { return (width > other.width && height > other.height) ? true : false; }
                inline bool operator <= (vector2d<T> other) { return (width <= other.width && height <= other.height) ? true : false; }
                inline bool operator >= (vector2d<T> other) { return (width >= other.width && height >= other.height) ? true : false; }
                inline bool operator == (vector2d<T> other) { return (width == other.width && height == other.height) ? true : false; }
                inline bool operator != (vector2d<T> other) { return (width != other.width && height != other.height) ? true : false; }

                inline vector2d<T> normalise()
                {
                    vector2d<T> tmp = *this;
                        T n = sqrt(width*width+height*height);
                        tmp.width /= n;
                        tmp.height /= n;
                    return tmp;
                }
                inline f32 getDistance(vector2d<T> i)
                {
                    return sqrtf((f32) ( ((width-i.width)*(width-i.width)) + ((height-i.height)*(height-i.height)) ));
                }

                inline vector2d<T> operator += (vector2d<T> other){ width += other.width; height += other.height; }
                inline vector2d<T> operator -= (vector2d<T> other){ width -= other.width; height -= other.height; }

                T width, height; // hauteur, largeur
            };

            typedef vector2d<u8>  vector2dc;
            typedef vector2d<f32> vector2df;
            typedef vector2d<int> vector2di;
            typedef vector2d<u32> vector2du;
            typedef vector2d<s32> vector2ds;

            template<typename T>
            inline vector2df convertToGl(vector2d<T> rec)
            {
                vector2df pos;
                    pos.width = (float)rec.width;
                    pos.height = (float)rec.height;
                return pos;
            }
        }
    }
}

#endif
